import request from '../utils/request.js'

// 客户申请相关API

/**
 * 创建客户申请
 */
export function createCustomerApplication(data) {
  return request({
    url: '/customer-management/api/customers',
    method: 'post',
    data
  })
}

/**
 * 更新客户申请
 */
export function updateCustomerApplication(customerId, data) {
  return request({
    url: `/customer-management/api/customers/${customerId}`,
    method: 'put',
    data
  })
}

/**
 * 删除客户申请
 */
export function deleteCustomerApplication(customerId) {
  return request({
    url: `/customer-management/api/customers/${customerId}`,
    method: 'delete'
  })
}

/**
 * 获取客户申请详情
 */
export function getCustomerApplicationById(customerId) {
  return request({
    url: `/customer-management/api/customers/${customerId}`,
    method: 'get'
  })
}

/**
 * 获取客户详情（包含所有相关信息）
 */
export function getCustomerDetailById(customerId) {
  return request({
    url: `/customer-management/api/customers/${customerId}/detail`,
    method: 'get'
  })
}

/**
 * 获取客户申请列表
 */
export function getCustomerList(params) {
  return request({
    url: '/customer-management/api/customers',
    method: 'get',
    params
  })
}

/**
 * 获取用户客户申请列表
 */
export function getUserCustomerApplications() {
  return request({
    url: '/customer-management/api/customers/user',
    method: 'get'
  })
}

/**
 * 获取待审批客户列表
 */
export function getPendingCustomerApplications() {
  return request({
    url: '/customer-management/api/customers/pending',
    method: 'get'
  })
}

/**
 * 提交客户申请（启动工作流）
 */
export function submitCustomerApplication(customerId) {
  return request({
    url: `/customer-management/api/customers/${customerId}/submit`,
    method: 'post'
  })
}

/**
 * 审批客户
 */
export function approveCustomer(processInstanceId) {
  return request({
    url: '/customer-management/api/customers/approve',
    method: 'post',
    params: { processInstanceId }
  })
}

/**
 * 拒绝客户申请
 */
export function rejectCustomer(processInstanceId, reason) {
  return request({
    url: '/customer-management/api/customers/reject',
    method: 'post',
    params: { processInstanceId, reason }
  })
}

/**
 * 获取待审批客户列表（当前用户）
 */
export function getPendingApprovalCustomers() {
  return request({
    url: '/customer-management/api/customers/pending',
    method: 'get'
  })
}

/**
 * 获取客户审批历史
 */
export function getCustomerApprovalHistory(customerId) {
  return request({
    url: `/customer-management/api/customers/${customerId}/approval-history`,
    method: 'get'
  })
}

/**
 * 获取客户流程信息
 */
export function getCustomerProcess(customerId) {
  return request({
    url: `/customer-management/api/customers/${customerId}/process`,
    method: 'get'
  })
}

/**
 * 获取客户流程步骤
 */
export function getCustomerProcessSteps(processInstanceId) {
  return request({
    url: `/customer-management/api/customers/process/${processInstanceId}/steps`,
    method: 'get'
  })
}

/**
 * 获取客户统计信息
 */
export function getCustomerStatistics() {
  return request({
    url: '/customer-management/api/customers/statistics',
    method: 'get'
  })
}

/**
 * 取消客户申请
 */
export function cancelCustomerApplication(customerId, reason) {
  return request({
    url: `/customer-management/api/customers/${customerId}/cancel`,
    method: 'post',
    params: { reason }
  })
}

/**
 * 获取我发起的客户申请列表
 */
export function getByCreateBy() {
  return request({
    url: '/customer-management/api/customers/getByCreateBy',
    method: 'get'
  })
}

/**
 * 获取历史已审批的客户申请列表
 */
export function getHistoryCustomerApplications() {
  return request({
    url: '/customer-management/api/customers/history',
    method: 'get'
  })
}
